package com.yuanfeng.activity.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.activity.entity.ActivityNoneTypeEntity;
import com.yuanfeng.activity.mapper.ActivityNoneTypeMapper;
import com.yuanfeng.activity.service.ActivityNoneTypeService;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ResponseResult;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class ActivityNoneTypeServiceImpl extends ServiceImpl<ActivityNoneTypeMapper, ActivityNoneTypeEntity>
    implements ActivityNoneTypeService{

    @Override
    public ResponseResult queryActivityNoneType() {
        List<ActivityNoneTypeEntity> list=this.baseMapper.selectNoneType();
        return ResponseResult.success(list);
    }

    @Override
    public ResponseResult updateNoneType(Map<String, Object> param) {
        if(null == param.get("displayOrder")){
            param.put("displayOrder",0);
        }
        if (null == param.get("noneType")) {
            ActivityNoneTypeEntity entity=new ActivityNoneTypeEntity();
            entity.setDisplayOrder(Integer.valueOf(param.get("displayOrder").toString()));
            entity.setNoneName(param.get("noneName").toString());
            this.baseMapper.insert(entity);
        } else {
            this.baseMapper.update(null,new LambdaUpdateWrapper<ActivityNoneTypeEntity>()
                                    .set(ActivityNoneTypeEntity::getNoneName,param.get("noneName").toString())
                                    .set(ActivityNoneTypeEntity::getDisplayOrder,Integer.valueOf(param.get("displayOrder").toString()))
                                    .eq(ActivityNoneTypeEntity::getNoneType,Integer.valueOf(param.get("noneType").toString())));
        }

        return ResponseResult.success(BizCodeEnume.OPERATION_SUCCESSFUL);
    }

    @Override
    public ResponseResult selectNotJoinType() {
        List<ActivityNoneTypeEntity> list = this.baseMapper.selectNotJoinType();
        return ResponseResult.success(list);
    }
}




